<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>滑动滚动条</title>
  <style>
    *{
      margin: 0;padding: 0;box-sizing: border-box;
    }.begbox{
      position: relative;
      width: 500px;top: 15px;
    }.box{
      width: 100%;
      height: 30px;
      border-radius: 50px;
      border: 1px solid black;
      overflow: hidden;
      margin: 40px auto;
    }.box-animtion{
      width: 10px;
      height: 100%;
      display: inline-block;background-color: aqua; border-radius: 50px;
    }.box-span{
      width: 40px;height: 40px;border-radius: 40px;background-color: red;display: inline-block;
     position: absolute;top: -5px;opacity: 0;cursor: pointer;
    }#maginBox{
      /* padding: 20px; */
      width: 500px;
      height: 60px;
      /* line-height: 60px; */
      margin: auto;
    }
  </style>
</head>
<body>
   <div id="maginBox">
    <div class="begbox">
      <div class="box">
        <div class="box-animtion"></div>
        <div class="box-span" id="box_span"></div>
      </div>
    </div>
   </div>
</body>
</html>
<script>
  window.addEventListener('load',function(){

  var box_js = document.querySelector('maginBox');
  maginBox.onmouseover = function(){
    box_span.style.opacity = '1'

  }
  maginBox.onmouseout = function(){
    box_span.style.opacity = '0'

  }
var offsetX,offsetY;
  //给红色框绑定鼠标按下拖动事件
  box_span.onmousedown = function(){
    // console.log('鼠标按下',this);
    offsetX = event.clientX - box_span.offsetLeft
    // this.mousemove = function(){
    //   console.log('',this);
    // }
    console.log('',offsetX);
  }

  function animtionFun(){
    
  }
  })
</script>